package com.smart.draw.plantuml.config;

import com.smart.draw.plantuml.servlet.*;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

/**
 * @Author xiaoqiang
 * @Version ServletConfig.java, v 0.1 2025年08月23日 01:15 xiaoqiang
 * @Description: TODO
 */
//@Configuration
public class ServletConfig {

    // PlantUmlServlet
    @Bean
    public ServletRegistrationBean<PlantUmlServlet> plantUmlServletRegistration() {
        ServletRegistrationBean<PlantUmlServlet> registrationBean = new ServletRegistrationBean<>(new PlantUmlServlet(), "/welcome", "/uml/*", "/form", "/start/*");
        registrationBean.setName("plantumlservlet");
        registrationBean.setLoadOnStartup(0);
        return registrationBean;
    }

    // ImgServlet (PNG)
    @Bean
    public ServletRegistrationBean<ImgServlet> imgServletRegistration() {
        ServletRegistrationBean<ImgServlet> registrationBean = new ServletRegistrationBean<>(new ImgServlet(), "/png/*", "/img/*");
        registrationBean.setName("imgservlet");
        return registrationBean;
    }

    // SvgServlet
    @Bean
    public ServletRegistrationBean<SvgServlet> svgServletRegistration() {
        ServletRegistrationBean<SvgServlet> registrationBean = new ServletRegistrationBean<>(new SvgServlet(), "/svg/*");
        registrationBean.setName("svgservlet");
        return registrationBean;
    }

    // PdfServlet
    @Bean
    public ServletRegistrationBean<PdfServlet> pdfServletRegistration() {
        ServletRegistrationBean<PdfServlet> registrationBean = new ServletRegistrationBean<>(new PdfServlet(), "/pdf/*");
        registrationBean.setName("pdfservlet");
        return registrationBean;
    }

    // EpsServlet
    @Bean
    public ServletRegistrationBean<EpsServlet> epsServletRegistration() {
        ServletRegistrationBean<EpsServlet> registrationBean = new ServletRegistrationBean<>(new EpsServlet(), "/eps/*");
        registrationBean.setName("epsservlet");
        return registrationBean;
    }

    // EpsTextServlet
    @Bean
    public ServletRegistrationBean<EpsTextServlet> epsTextServletRegistration() {
        ServletRegistrationBean<EpsTextServlet> registrationBean = new ServletRegistrationBean<>(new EpsTextServlet(), "/epstext/*");
        registrationBean.setName("epstextservlet");
        return registrationBean;
    }

    // Base64Servlet
    @Bean
    public ServletRegistrationBean<Base64Servlet> base64ServletRegistration() {
        ServletRegistrationBean<Base64Servlet> registrationBean = new ServletRegistrationBean<>(new Base64Servlet(), "/base64/*");
        registrationBean.setName("base64servlet");
        return registrationBean;
    }

    // AsciiServlet (TXT)
    @Bean
    public ServletRegistrationBean<AsciiServlet> asciiServletRegistration() {
        ServletRegistrationBean<AsciiServlet> registrationBean = new ServletRegistrationBean<>(new AsciiServlet(), "/txt/*");
        registrationBean.setName("asciiservlet");
        return registrationBean;
    }

    // ProxyServlet
    @Bean
    public ServletRegistrationBean<ProxyServlet> proxyServletRegistration() {
        ServletRegistrationBean<ProxyServlet> registrationBean = new ServletRegistrationBean<>(new ProxyServlet(), "/proxy");
        registrationBean.setName("proxyservlet");
        return registrationBean;
    }

    // OldProxyServlet
    @Bean
    public ServletRegistrationBean<OldProxyServlet> oldProxyServletRegistration() {
        ServletRegistrationBean<OldProxyServlet> registrationBean = new ServletRegistrationBean<>(new OldProxyServlet(), "/proxy/*");
        registrationBean.setName("oldproxyservlet");
        return registrationBean;
    }

    // MapServlet
    @Bean
    public ServletRegistrationBean<MapServlet> mapServletRegistration() {
        ServletRegistrationBean<MapServlet> registrationBean = new ServletRegistrationBean<>(new MapServlet(), "/map/*");
        registrationBean.setName("mapservlet");
        return registrationBean;
    }

    // CheckSyntaxServlet
    @Bean
    public ServletRegistrationBean<CheckSyntaxServlet> checkSyntaxServletRegistration() {
        ServletRegistrationBean<CheckSyntaxServlet> registrationBean = new ServletRegistrationBean<>(new CheckSyntaxServlet(), "/check/*");
        registrationBean.setName("checkservlet");
        return registrationBean;
    }

    // LanguageServlet
    @Bean
    public ServletRegistrationBean<LanguageServlet> languageServletRegistration() {
        ServletRegistrationBean<LanguageServlet> registrationBean = new ServletRegistrationBean<>(new LanguageServlet(), "/language");
        registrationBean.setName("languageservlet");
        return registrationBean;
    }

    // AsciiCoderServlet
    @Bean
    public ServletRegistrationBean<AsciiCoderServlet> asciiCoderServletRegistration() {
        ServletRegistrationBean<AsciiCoderServlet> registrationBean = new ServletRegistrationBean<>(new AsciiCoderServlet(), "/coder/*");
        registrationBean.setName("asciicoderservlet");
        return registrationBean;
    }

    // PlantUmlUIHelperServlet
    @Bean
    public ServletRegistrationBean<PlantUmlUIHelperServlet> plantUmlUIHelperServletRegistration() {
        ServletRegistrationBean<PlantUmlUIHelperServlet> registrationBean = new ServletRegistrationBean<>(new PlantUmlUIHelperServlet(), "/ui-helper/*");
        registrationBean.setName("plantumluihelperservlet");
        return registrationBean;
    }

    // MetadataServlet
    @Bean
    public ServletRegistrationBean<MetadataServlet> metadataServletRegistration() {
        ServletRegistrationBean<MetadataServlet> registrationBean = new ServletRegistrationBean<>(new MetadataServlet(), "/metadata/*");
        registrationBean.setName("metadataservlet");
        return registrationBean;
    }
}
